package side_server;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import talk_server.Talker;



public class Server_Join {
	private String 	msg;
	
	public Server_Join(Talker talker) throws UnknownHostException, IOException
	{
		super();
		talker.setTimeOut(10000);
		System.out.println("SENDING WHO");
		talker.write("WHO"); //Invio il messaggio di conferma
		msg = talker.read(); //Attendo i parametri del peer
		System.out.println("RECEIVED: " + msg);
		String[] peer = msg.split(" ");
		//Aggiungo il peer alla lista
		if (Server_Launch.getInstance().getPeerCount()<20)
			Server_Launch.getInstance().addPeer(peer[0], Integer.parseInt(peer[1]));
		System.out.println("SENDING OK");
		talker.write("OK"); //Confermo l'operazione
	}
}
